home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / UNITS / YAKFONT.CPP < prev    next >
C/C++ Source or Header  |  1992-12-09  |  1KB  |  53 lines

  1. #include "yakfont.h"
  2. #include "xrect.h"
  3. #include "xline.h"
  4. #include "string.h"
  5. #include "conio.h"
  6.  
  7. void yakFont::load(char * filename, yakLib * myYakLib)
  8. {
  9.   int sizeOfBuffer;
  10.   if (fontData)
  11.     delete fontData;
  12.   if (myYakLib)
  13.   {
  14.     fontData = myYakLib->loadToMem(filename);
  15.     sizeOfBuffer = myYakLib->fileSize(filename);
  16.   }
  17.   else
  18.   {
  19.     ifstream myInStream(filename, ios::binary | ios::in);
  20.     myInStream.seekg(0, ios::end);
  21.     sizeOfBuffer = myInStream.tellg(); //not really!  Just using it!
  22.     fontData = new byte[sizeOfBuffer];
  23.     myInStream.seekg(0);
  24.     myInStream.read(fontData, sizeOfBuffer);
  25.     myInStream.close();
  26.   }
  27.   startChar = *(word *)fontData;
  28.   charHeight = *(byte *)(fontData+2);
  29.   charWidth = *(byte *)(fontData+3);
  30.   numberOfChars = (sizeOfBuffer - 4) / charHeight; //the real numo'Chars
  31. }
  32.  
  33. void yakFont::registerMe(void)
  34. {
  35.   x_register_userfont(fontData);
  36. }
  37.  
  38.  
  39.  
  40. void yakFont::use(void)
  41. {
  42.   registerMe();
  43.   x_set_font(FONT_USER);
  44. }
  45.  
  46. void yakFont::save(char * filename)
  47. {
  48.   ofstream myOutStream(filename, ios::binary | ios::in);
  49.   myOutStream.write(fontData, numberOfChars*charHeight + 4);
  50.   myOutStream.close();
  51. }
  52.  
  53.